/**
 * Created by liyun on 2016/12/23.
 */
app.controller('MyLinkingCtrl', function ($scope, $state, $stateParams, $ionicHistory, $timeout, BthSevice,$rootScope,$ionicConfig) {

    $scope.devices = BthSevice.scanDevices;
    //todo 在点击设备连接后停止搜索
    // console.log($scope.devices);

    $scope.connectBth = function (address, v) { //选择的蓝牙地址和蓝牙信息
        localStorage.setItem(address, JSON.stringify(v)); // 本地存储当前连接的蓝牙信息
        localStorage.setItem('addr', address); // 本地存储当前连接的蓝牙
        BthSevice.connect(address, function (res) {
            if (res.success) { // 连接成功
                $timeout(function () { //获取上次的理疗状态
                    BthSevice.getLastSPA();
                }, 3000);
                // $ionicHistory.clearHistory();
                $ionicHistory.nextViewOptions({
                    disableAnimate: true,
                    disableBack: true,
                    historyRoot: true
                });
                $rootScope.connected = true;
                $rootScope.$broadcast('loadData', 'on');
                $rootScope.$broadcast('sendToMenu', 'on');
                $state.go('app.BiGuangBao');
            } else { // 失败提示重试

            }
        });
    };

    // $scope.$on('$ionicView.enter', function(){

        $ionicConfig.views.swipeBackEnabled(false);

    // });

});
